#!/usr/bin/env bash

setup_env() {
    yaml_file=$(find ~/.artifacts -name "environment*.yaml" | head -n 1)

    echo "YAML file..."
    cat "${yaml_file}"

    mkdir -p /tmp/out;

    cp "${yaml_file}" /tmp/out

    mamba env create -n legate -f "$yaml_file"

    mamba uninstall -yn legate numpy

    mamba install -yn legate -c ~/.artifacts/legate_core -c conda-forge -c nvidia legate-core

    mamba activate legate
}

build_cunumeric_all() {
    set -xeo pipefail

    setup_env;
    cd ~/cunumeric;
    conda info;

    set -xeuo pipefail;
    printf "\n\n\n\n********* BUILDING CUNUMERIC CPP *********\n"
    build-cunumeric-cpp;
    printf "\n\n\n\n********* BUILDING CUNUMERIC WHEEL *********\n"
    build-cunumeric-wheel;
    printf "\n\n\n\n********* BUILDING CUNUMERIC CONDA *********\n"
    build-cunumeric-conda;
}

(build_cunumeric_all "$@");
